<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="js/vue.js"></script>
</head>

<body>
    <h1>输入框输入自动获得焦点</h1>
    <div id="app">
        <label>
            用户名:
            <input type="text" v-focus>
        </label>
    </div>
</body>
<script>
    Vue.directive('focus', {
        inserted: function (el) {
            el.focus()
        }
    })
    const vm = new Vue({
        el: '#app',
    })
</script>

</html>